﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Comm;

namespace ConsoleFtpSync
{
    class Program
    {
        static void Main(string[] args)
        {
            string strFtpIP = System.Configuration.ConfigurationSettings.AppSettings["FtpServerIP"].ToString();
            string strPath = System.Configuration.ConfigurationSettings.AppSettings["FtpRemotePath"].ToString();
            string strAcc = System.Configuration.ConfigurationSettings.AppSettings["FtpUserID"].ToString();
            string strPsd = System.Configuration.ConfigurationSettings.AppSettings["FtpPassword"].ToString();
            string strBackupPath = System.Configuration.ConfigurationSettings.AppSettings["BackupPath"].ToString();

            FtpHelper ftp = new FtpHelper(strFtpIP, strPath, strAcc, strPsd);
            try
            {
                //获取FTP文件列表
                string[] fileArray = ftp.GetFileList("");
                //获取本地文件列表
                string[] files = Directory.GetFiles(strBackupPath);

                string strLocalFileName = "";
                foreach (string ftpFile in fileArray)
                {
                    strLocalFileName = strBackupPath + "\\" + ftpFile;
                    if (Array.IndexOf(files, strLocalFileName) < 0)
                    {
                        ftp.Download(strBackupPath, ftpFile);
                        Console.WriteLine(ftpFile+"下载成功");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
    }
}
